package com.desire.homework;

import java.util.Random;
import java.util.Scanner;

/**
 * @author desire
 */
public class _13_猜数字游戏 {
    public static void main(String[] args) {
        System.out.println("!!!欢迎游玩猜数字游戏(0:退出游戏)!!!");

        int count = 0;

        Scanner sc = new Scanner(System.in);
        Random random = new Random();

        int num = random.nextInt(100) + 1;

        System.out.print("请输入[1-100]的整数数字: ");

        while (true) {
            int guess = sc.nextInt();
            if (guess == -1) {
                System.out.println("退出游戏");
                return;
            }
            count++;
            if (guess < num) {
                System.out.print("猜小了,请重新输入你要猜的数字: ");
            } else if (guess > num) {
                System.out.print("猜大了,请重新输入你要猜的数字: ");
            } else {
                System.out.printf("\n恭喜你猜对了,一共用了%d次", count);
                break;
            }
        }
    }
}
